package com.bwie.conferenceroom.controller;

import com.bwie.common.domain.Equipment;
import com.bwie.common.domain.request.ConferenceRoomReq;
import com.bwie.common.domain.request.SaveOrUpdConferenceRoomReq;
import com.bwie.common.domain.response.ConferenceRoomRes;
import com.bwie.common.domain.response.MeetingRoomAreaRes;
import com.bwie.common.domain.response.OccupationRes;
import com.bwie.common.domain.response.UpdConferenceRoomRes;
import com.bwie.common.result.Result;
import com.bwie.common.utils.OssUtil;
import com.bwie.conferenceroom.service.ConferenceRoomService;
import com.github.pagehelper.PageHelper;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Log4j2
public class ConferenceRoomController {
    @Autowired
    private ConferenceRoomService service;

    @Autowired
    HttpServletRequest request;

    @Autowired
    private OssUtil ossUtil;

    /**
     * 获取会议室列表
     * @param conferenceRoomReq
     * @return
     */
    @PostMapping("getConferenceRoomList")
    public Result getConferenceRoomList(@RequestBody ConferenceRoomReq conferenceRoomReq){
        log.info("功能名称：获取会议室列表，请求url：{}，请求方式：{}，请求参数：{}",request.getRequestURI(),request.getMethod(),conferenceRoomReq);
        List<ConferenceRoomRes> list=service.getConferenceRoomList(conferenceRoomReq);
        Result<List<ConferenceRoomRes>> result = Result.success(list);
        log.info("功能名称：获取会议室列表，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }

    /**
     * 获取所有会议室设备
     * @return
     */
    @GetMapping("getEquipment")
    public Result getEquipment(){
        log.info("功能名称：获取所有会议室设备，请求url：{}，请求方式：{}",request.getRequestURI(),request.getMethod());
        List<Equipment> list=service.getEquipment();
        Result<List<Equipment>> result = Result.success(list);
        log.info("功能名称：获取所有会议室设备，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }

    /**
     * 图片上传
     * @param file
     * @return
     */
    @PostMapping("getImageUrl")
    public Result getImageUrl(MultipartFile file){
        String s = ossUtil.uploadMultipartFile(file);
        return Result.success(s);
    }

    /**
     * 获取所有区域以及楼栋
     * @return
     */
    @GetMapping("getMeetingRoomArea")
    public Result getMeetingRoomArea(){
        log.info("功能名称：获取所有区域以及楼栋，请求url：{}，请求方式：{}",request.getRequestURI(),request.getMethod());
        List<MeetingRoomAreaRes> list=service.getMeetingRoomArea();
        Result<List<MeetingRoomAreaRes>> result = Result.success(list);
        log.info("功能名称：获取所有区域以及楼栋，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }

    /**
     * 新建/修改会议室
     * @param saveOrUpdConferenceRoomReq
     * @return
     */
    @PostMapping("saveOrUpdConferenceRoom")
    public Result saveOrUpdConferenceRoom(@RequestBody SaveOrUpdConferenceRoomReq saveOrUpdConferenceRoomReq){
        log.info("功能名称：新建/修改会议室，请求url：{}，请求方式：{}，请求参数：{}",request.getRequestURI(),request.getMethod(),saveOrUpdConferenceRoomReq);
        service.saveOrUpdConferenceRoom(saveOrUpdConferenceRoomReq);
        Result<Object> result = Result.success();
        log.info("功能名称：新建/修改会议室，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }

    /**
     * 根据id查询会议室详情
     * @param id
     * @return
     */
    @GetMapping("selectConferenceRoomById/{id}")
    public Result selectConferenceRoomById(@PathVariable Integer id){
        log.info("功能名称：根据id查询会议室详情，请求url：{}，请求方式：{}，请求参数：{}",request.getRequestURI(),request.getMethod(),id);
        UpdConferenceRoomRes updConferenceRoomRes=service.selectConferenceRoomById(id);
        Result<UpdConferenceRoomRes> result = Result.success(updConferenceRoomRes);
        log.info("功能名称：根据id查询会议室详情，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }

    /**
     * 获取占用会议室列表
     * @return
     */
    @GetMapping("getOccupationList")
    public Result getOccupationList(){
        log.info("功能名称：获取占用会议室列表，请求url：{}，请求方式：{}",request.getRequestURI(),request.getMethod());
        List<OccupationRes> list=service.getOccupationList();
        Result<List<OccupationRes>> result = Result.success(list);
        log.info("功能名称：获取占用会议室列表，请求url：{}，请求方式：{}，响应结果：{}",request.getRequestURI(),request.getMethod(),result);
        return result;
    }
}
